package voucher_creator.write.excel;

import java.io.File;
import jxl.*;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class Excel {

	public String readExcel(String excel_file, String sheet_name,
			int row, int column) {
		String cellData = new String();
		try {
			Workbook workbook = Workbook.getWorkbook(new File(excel_file));
			Sheet sheet = workbook.getSheet(sheet_name);
			Cell cell = sheet.getCell(column, row);
			cellData = cell.getContents();
			workbook.close();
		} catch (Exception e) {
			System.err.println("readExcel ->" + e.getMessage());
		}
		return cellData;
	}

	public void writeExcel(String excel_file, String sheet_name, int row,
			int column, String data) {
		try {
			Workbook target_workbook = Workbook
					.getWorkbook(new File(excel_file));
			WorkbookSettings settings = new WorkbookSettings();
			settings.setSuppressWarnings(true);
			WritableWorkbook workbook = Workbook.createWorkbook(new File(
					excel_file), target_workbook, settings);
			target_workbook.close();
			WritableSheet sheet = workbook.getSheet(sheet_name);
			jxl.write.Label label = new jxl.write.Label(column, row, data);
			sheet.addCell(label);
			workbook.write();
			workbook.close();
		} catch (Exception e) {
			System.err.println("writeExcel ->" + e.getMessage());
		}
	}

}
